
import { _decorator, Component, Node, MeshRenderer } from 'cc';
import yyComponent from '../../Script/Common/yyComponent';
import { GlobalEnum } from '../../Script/GameSpecial/GlobalEnum';
import { Role } from './Role';
const { ccclass, property } = _decorator;

@ccclass('BaseTransform')
export class BaseTransform extends yyComponent {

    onLoad() {
        let mesh = this.node.getComponent(MeshRenderer);
        if (!!mesh) {
            mesh.mesh.struct.minPosition = null;
            mesh.mesh.struct.maxPosition = null;
        }
        let meshs = this.node.getComponentsInChildren(MeshRenderer);
        for (let i = meshs.length - 1; i >= 0; --i) {
            meshs[i].mesh.struct.minPosition = null;
            meshs[i].mesh.struct.maxPosition = null;
        }
    }

    protected initSub() {
        this.initCollScope();
        this.initDirtyFlags();
    }
    protected resetSub() {
        this.resetCollScope();
        this.resetDirtyFlags();
    }

    public checkColl(role: Role) {
        return role.minRadian <= this.maxRadian && role.maxRadian >= this.minRadian;
    }
    public onColl(data?) {

    }

    //#region 碰撞范围
    public canColl: boolean = true;
    //底部弧度范围
    public minRadian: number;
    public maxRadian: number;
    public minZ: number;
    public maxZ: number;
    protected initCollScope() {
        this.canColl = true;
        this.minRadian = 0;
        this.maxRadian = 0;
        this.minZ = 0;
        this.maxZ = 0;
    }
    protected resetCollScope() {
        this.canColl = true;

    }
    //#endregion

    //#region 属性变化标记
    /**属性变化标记 */
    protected dirtyFlags: GlobalEnum.DirtyType = GlobalEnum.DirtyType.all;
    protected initDirtyFlags() {
        this.dirtyFlags = GlobalEnum.DirtyType.all;
    }
    /**重置变化标记 */
    protected resetDirtyFlags() {
        this.dirtyFlags = GlobalEnum.DirtyType.all;
    }
    /**读取指定变化标记 */
    protected getDirtyFlags(type: GlobalEnum.DirtyType): boolean {
        return (this.dirtyFlags & type) > 0;
    }
    /**设置指定变化标记 */
    protected setDirtyFlags(type: GlobalEnum.DirtyType) {
        this.dirtyFlags |= type;
    }
    /**清除指定变化标记 */
    protected clearDirtyFlags(type: GlobalEnum.DirtyType) {
        this.dirtyFlags &= (~type);
    }
    //#endregion


}
